//  该文件是Count组件的Reducer,专门为Count组件提供服务，本身即为函数
/**
 * count组件的Reducer
 *
 * @param preState  上一次保存的状态，初始化时时undefined
 * @param action 操作 {type:'xx',payload:'数据，可选'}
 * @returns 返回处理后的一个新的state
 */

import { anyAction } from './interface';
import { ADD_PERSON } from '../contant/person';

export interface PreState {
    id: string;
    name: string;
    age: number;
}
export interface Person {
    persons: PreState;
}
export interface Action {
    type: string;
    payload: anyAction;
}

const preState: Person = {
    persons: {
        id: '',
        name: '',
        age: 0
    }
}; // 初始化count

const Personal = (state: Person = preState, action: Action) => {
    console.log('x6', action, 'state', state);
    const { type, payload } = action;
    switch (type) {
        case ADD_PERSON:
            return { ...state, persons: payload };
        default:
            return preState;
    }
};

export default Personal;
